package org.example.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.mapper.CompanyMapper;
import org.example.pojo.Company;
import org.example.pojo.Job;
import org.example.pojo.PageBean;
import org.example.pojo.Resume;
import org.example.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyMapper companyMapper;

    @Override
    public void insertCompany(Company company) {
        companyMapper.insertCompany(company);
    }

    @Override
    public Company findCompanyById(Integer companyId) {
        return companyMapper.findCompanyById(companyId);
    }

    @Override
    public List<Company> selectCompanyByName(String companyName) {
        return companyMapper.selectCompanyByName(companyName);
    }

    @Override
    public PageBean<Company> getCompanyList(Integer companyId, String name, Integer pageNum, Integer pageSize) {
        //1.创建一个PageBean对象
        PageBean<Company> pb = new PageBean<>();

        //2.开启分页插件功能
        PageHelper.startPage(pageNum, pageSize);

        //将数据转为Page类型
        try{
            List<Company> companies =  companyMapper.selectByUserIdAndName(companyId, name);
            Page<Company> page = (Page<Company>) companies;

            //把数据填充到PageBean对象中
            pb.setTotal(page.getTotal());
            pb.setItem(page.getResult());
            return pb;
        }catch (Exception e){
            System.out.println(e.getMessage());
            return null;
        }
    }

    @Override
    public Company selectByCompanyId(Integer companyId) {
        return companyMapper.selectByCompanyId(companyId);
    }

    @Override
    public void updateCompany(Company company) {
        companyMapper.updateCompany(company);
    }

    @Override
    public Company getCompanyById(Integer companyId) {
        return companyMapper.getCompanyById(companyId);
    }

    @Override
    public List<Company> getCompanyJob(Integer companyId) {
        return companyMapper.getCompanyJob(companyId);
    }

    @Override
    public Integer getCount(List<Integer> counts) {
        return companyMapper.getCount(counts);
    }

    @Override
    public List<Job> getTopCompany(String salary, String city, Integer minSalary, Integer maxSalary) {
        return companyMapper.getTopCompany(salary, city, minSalary, maxSalary);
    }

}
